<h1 class="page-header">
    <small>新增菜单</small>
</h1>
<hr/>
<div class="panel panel-inverse" data-sortable-id="form-stuff-1">
    <div class="panel-heading">
        <h4 class="panel-title">菜单表单</h4>
    </div>
    <div class="panel-body">
        <form id="sourceForm" name="sourceForm" action="" method="post" class="form-horizontal">
            <div class="form-group">
                <label class="col-md-3 control-label">菜单名称</label>

                <div class="col-md-9">
                    <input type="text" id="name" class="form-control" name="name" value="" placeholder="菜单名称 2-10位"
                           rangelength="2,10" required/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">菜单地址</label>

                <div class="col-md-9">
                    <input type="text" id="sourceCode" class="form-control" name="sourceCode" value=""
                           placeholder="菜单地址 6-50位" rangelength="6,50" required/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">菜单排序</label>

                <div class="col-md-9">
                    <input type="text" id="style" class="form-control" name="style" value="" placeholder="菜单排序,数字类型"
                           required/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">是否菜单</label>

                <div class="col-md-9">
                    <select class="form-control" name="isMenu" id="isMenu" required>
                        <option value="">--请选择--</option>
                        <option value="0">否</option>
                        <option value="1">是</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">是否日志</label>

                <div class="col-md-9">
                    <select class="form-control" name="isLog" id="isLog" required>
                        <option value="">--请选择--</option>
                        <option value="0">否</option>
                        <option value="1">是</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">菜单状态</label>

                <div class="col-md-9">
                    <select class="form-control" name="status" id="status" required>
                        <option value="">--请选择--</option>
                        <option value="A">有效</option>
                        <option value="D">无效</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">菜单描述</label>

                <div class="col-md-9">
                    <textarea class="form-control" placeholder="请填写菜单描述.... 1-100位" rows="5" name="description"
                              rangelength="1,100"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">上级菜单</label>

                <div class="col-md-9">
                    <select class="form-control" name="parentCode" id="parentCode">
                        <option value="">---请选择---</option>
                    <#if sourceTree?has_content && sourceTree?exists>
                        <#list sourceTree as st>
                            <option value="${st.id}">${st.name}</option>
                        </#list>
                    </#if>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">图标样式</label>

                <div class="col-md-9">
                    <input type="text" id="icon" class="form-control" name="icon" value="" placeholder="菜单图标"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label"></label>

                <div class="col-md-9">
                    <button type="button" id="submitButton" class="btn btn-sm btn-success">提交</button>
                </div>
            </div>
        </form>
        <script type="application/javascript">

            $(function () {

                $('#submitButton').click(function () {
                    $('#sourceForm').submit();
                })

                $('#sourceForm').validate({
                    rules: {
                        style: {
                            isNumber: true
                        },
                        parentCode: {
                            isNumber: true
                        }
                    },
                    messages: {
                        style: {
                            isNumber: "请输入数字"
                        },
                        parentCode: {
                            isNumber: "请输入数字"
                        }
                    },
                    errorPlacement: function (error, element) {
                        error.appendTo(element.parent());
                    },
                    submitHandler: function () {
                        postDataByForm('${rc.contextPath}/source/add', 'displayArea', 'sourceForm');
                    }
                })
            })
        </script>